package com.tind.wyf.baselib.base;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.tind.wyf.baselib.utils.AppManager;
import com.tind.wyf.baselib.utils.ToActivity;
import com.tind.wyf.baselib.utils.bar.StatusBarUtil;


/**
 * <pre>
 *     @author : tind
 *     @e-mail : xxx@xx
 *     @time   : 2017/11/24
 *     @desc   : BaseActivity
 *              {@link #}
 *     @version: 1.0
 * </pre>
 */

public abstract class BaseActivity extends AppCompatActivity {
    protected final String TAG = this.getClass().getName();
    protected Context mContext;
    protected ToActivity.Builder mToActivity;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (initBundle(getIntent().getExtras())) {
            //沉浸式代码配置
            StatusBarUtil.setTranslucentStatus(this);
            setContentView(getLayoutId());
            mContext = this;
            AppManager.getAppManager().addActivity(this);
            mToActivity = ToActivity.with(this);
            initView();
            initData();
        } else {
            finish();
        }
    }


    public <T extends View> T $(@IdRes int viewId) {
        return (T) findViewById(viewId);
    }

    /**
     * 布局layoutId
     *
     * @return
     */
    @LayoutRes
    protected abstract int getLayoutId();

    /**
     * 界面设置
     */
    protected abstract void initView();

    /**
     * 数据加载
     */
    protected abstract void initData();

    /**
     * 数据接收
     *
     * @param extras
     * @return
     */
    protected boolean initBundle(Bundle extras) {
        return true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        mToActivity.setActivity(this);
    }

    @Override
    protected void onDestroy() {
        AppManager.getAppManager().finishActivity();
        super.onDestroy();
    }

}
